package model.empresa;

import java.io.Serializable;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import model.tipolixo.TipoLixo;
import com.sun.xml.bind.CycleRecoverable;

@Entity
@Table(name="empresa")
public class Empresa implements Serializable, CycleRecoverable {


     private Integer id;
     private String cnpj;
     private String nomeFantasia;
     private String razaoSocial;
     private String endereco;
     private String nrEndereco;
     private String cep;
     private String telefone;
     private String fax;
     private String email;
     private String site;
     private List<TipoLixo> tipoLixo;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID_EMPRESA")
    public Integer getId() {
        return this.id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @Column(name="CNPJ", nullable=false, length=14)
    public String getCnpj() {
        return this.cnpj;
    }

    public void setCnpj(String cnpj) {
        this.cnpj = cnpj;
    }

    @Column(name="NOME_FANTASIA", nullable=false, length=100)
    public String getNomeFantasia() {
        return this.nomeFantasia;
    }

    public void setNomeFantasia(String nomeFantasia) {
        this.nomeFantasia = nomeFantasia;
    }

    @Column(name="RAZAO_SOCIAL", nullable=false, length=100)
    public String getRazaoSocial() {
        return this.razaoSocial;
    }

    public void setRazaoSocial(String razaoSocial) {
        this.razaoSocial = razaoSocial;
    }

    @Column(name="ENDERECO", nullable=false, length=150)
    public String getEndereco() {
        return this.endereco;
    }

    public void setEndereco(String endereco) {
        this.endereco = endereco;
    }

    @Column(name="NR_ENDERECO", length=10)
    public String getNrEndereco() {
        return this.nrEndereco;
    }

    public void setNrEndereco(String nrEndereco) {
        this.nrEndereco = nrEndereco;
    }

    @Column(name="CEP", nullable=false, length=8)
    public String getCep() {
        return this.cep;
    }

    public void setCep(String cep) {
        this.cep = cep;
    }

    @Column(name="TELEFONE", length=11)
    public String getTelefone() {
        return this.telefone;
    }

    public void setTelefone(String telefone) {
        this.telefone = telefone;
    }

    @Column(name="FAX", length=11)
    public String getFax() {
        return this.fax;
    }

    public void setFax(String fax) {
        this.fax = fax;
    }

    @Column(name="EMAIL", length=50)
    public String getEmail() {
        return this.email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @Column(name="SITE", length=50)
    public String getSite() {
        return this.site;
    }

    public void setSite(String site) {
        this.site = site;
    }

    @ManyToMany(fetch=FetchType.LAZY, cascade=CascadeType.ALL)
    @JoinTable(name="emp_tipo_lixo",
            joinColumns={@JoinColumn(name="ID_EMPRESA")},
            inverseJoinColumns={@JoinColumn(name="ID_TIPO_LIXO")})
    public List<TipoLixo> getTipoLixo() {
        if(tipoLixo == null){
            tipoLixo = new ArrayList<TipoLixo>();
        }
        return this.tipoLixo;
    }

    public void setTipoLixo(List<TipoLixo> tipoLixo) {
        this.tipoLixo = tipoLixo;
    }
    
    @Override
    public Object onCycleDetected(Context cntxt) {
        System.out.println("CycleRecoverable.onCycleDetected # ".concat(this.toString()));
        Empresa n = new Empresa();
        n.setId(this.getId());
        return n;
    }

}